<%@ page pageEncoding="UTF-8"%>
<%@ include file="../commons/head.jsp"%>
<title>Java函数</title>
</head>
<body>
<div>
	<br />
	<p>switch函数</p>
	<input type="number" id="switch-test" onchange="testjijie();">
	测试季节
	<input type="text" id="switch-result">
	<p>substring函数</p>
	<input type="text" id="substring-test" onchange="testjiequ();">
	截取最后一位
	<input type="text" id="substring-result1">
	截取前三个字符
	<input type="text" id="substring-result2">
</div>
<script type="text/javascript">
	function testjijie(){
		var month = $("#switch-test").val();
		$.ajax({
			url:"${pageContext.request.contextPath}/huangyan/switchtest",
			contentType: "application/json; charset=utf-8",
			method:'',
			data:{"month":month},
			dataType:'json',
			complate:  function(XMLHttpRequest){
				alert("准备就绪");
			},
			success:function(data){debugger
				$("#switch-result").val(data[1]);
			},
			error:function(XMLHttpRequest, textStatus, errorThrown){
				alert("出错了");
			}
		});
	}
	function testjiequ(){
		var str = $("#substring-test").val();
		$.ajax({
			url:"${pageContext.request.contextPath}/huangyan/substringtest",
			contentType: "application/json; charset=utf-8",
			method:'',
			data:{"str":str},
			dataType:'json',
			complate:  function(XMLHttpRequest){
				alert("准备就绪");
			},
			success:function(data){debugger
				$("#substring-result1").val(data[1]);
				if(data[2] != null){
					$("#substring-result2").val(data[2]);
				}else{
					$("#substring-result2").val("输入的字符串长度小于4");
				}
			},
			error:function(XMLHttpRequest, textStatus, errorThrown){
				alert("出错了");
			}
		});
	}
</script>
</body>
</html>